package day0220;

public class Demo01 {


    public static void keepAnimal(Animal animal){
        animal.say();
        if (animal instanceof Cat) {
            Cat cat = (Cat) animal;
            cat.catchMouse();
        } else if (animal instanceof Dog) {
            Dog dog = (Dog) animal;
            dog.look();
        }
    }

    public static Animal getAnimal() {
//        return new Animal();
//        return new Dog();
//        return new Cat();
        return new PussyCat();
    }

    public static void main(String[] args) {
//        Animal animal = new Animal();
//        Dog animal = new Dog();
//        Cat animal = new Cat();
        PussyCat animal = new PussyCat();
        keepAnimal(animal);


    }
}


class PussyCat extends Cat{

}

class Person {

    public void keepAnimal(Animal animal){
        animal.say();
//        if (animal instanceof Cat) {
//            Cat cat = (Cat) animal;
//            cat.catchMouse();
//        } else if (animal instanceof Dog) {
//            Dog dog = (Dog) animal;
//            dog.look();
//        }

        if (animal instanceof Cat cat){
            cat.catchMouse();
        } else if (animal instanceof Dog dog) {
            dog.look();
        }
    }

    public Animal getAnimal() {
        return new Animal();
    }

}

class Student extends Person{

    @Override
    public Dog getAnimal(){
        return new Dog();
    }
}


